package org.wattdepot.cli;

import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.client.WattDepotClientException;

/**
 * Junit test class for TestListTotalCommandCli.
 * 
 * @author Dean Kim
 * 
 */
public class TestListTotalCommandCli {
  
  ListTotalCommandCli lsc;
  WattDepotClient client;
  
  /**
   * Initialize test environment.
   * @throws Exception Throw exception.
   */
  @Before
  public void setUp() throws Exception {
    lsc = new ListTotalCommandCli();
    client = new WattDepotClient("http://server.wattdepot.org:8182/wattdepot/");
  }
  
  /**
   * Unit test to verify input List commands at the interface point.
   */
  @Test
  public void testProcessCommand() {
    final String LIST_TOTAL_COMMAND_ERROR = "total usage error. Usage: total "
      + "[carbon|energy] {source} day {day} sampling-interval {minutes}";

    String[] listCommand = {"TOTAL", "CARBON", "SIM_WAIAU_8",
        "DAY", "2009-11-15", "SAMPLING-INTERVAL", "30", "ADDITIONAL"};
    String result;
    try {
      result = lsc.processCommand(client, listCommand);
      assertEquals("test total additional arg", result, LIST_TOTAL_COMMAND_ERROR);
      listCommand = new String[] {"TOTAL", "Nonvalid", "SIM_WAIAU_8",
          "DAY", "2009-11-15", "SAMPLING-INTERVAL", "30"};
      result = lsc.processCommand(client, listCommand);
      assertEquals("test total nonvalid", result, LIST_TOTAL_COMMAND_ERROR);
    }
    catch (WattDepotClientException e) {
      e.printStackTrace();
    }
  }

}
